<?php
/**
 * Celebrio FileSystem module
 *
 * @copyright  Copyright (c) 2011 Celebrio Software
 * @package    Celebrio
 * @subpackage FileSystem
 */
namespace Celebrio\FileSystem;

use Nette\Object;

use Celebrio\FileSystem\Drivers\Local;
use Celebrio\FileSystem\Drivers\GDocs;
use Albireo\Modules\AzureStorage;
use Celebrio\FileSystem\Drivers\AzureCelebrio;

use InvalidStateException;
use NotSupportedException;

/**
 * The factory selects, creates and returns the instances of FileSystem drivers
 * (i.e. classes which work with the specific type of file storage, for example
 * Local for local server filesystem or GDocs for Google documents storage).
 *
 * @author pavel, honza
 */
class FileSystemDriverFactory extends Object {
    
    public function getDriverToTheFile(DataFile $file) {
        $storageType = $file->getFstorageName();
        $driver = null;
        
        if ($storageType == "local") {
            $driver = new Local();
        } elseif ($storageType == "gdocs") {
            $driver = new GDocs();
        } elseif ($storageType == "azureStorage") {
            $driver = new AzureStorage();
        } elseif ($storageType == "azureCelebrio") {
            $driver = new AzureCelebrio();
        } else {
            throw new InvalidStateException ("Required fstorage driver for $storageType is not available.");
        }
        
        return $driver;
    }
    
    //TODO: Please, make me prettier.
    public function getDriverViaName($driver) {
        if($driver === "gdocs") {
            return new GDocs();
        } elseif($driver === "local") {
            return new Local();
        } elseif($driver === "azureStorage") {
            return new AzureStorage();
        } elseif ($driver === "azureCelebrio") {
            return new AzureCeleb();
        } else {
            throw new NotSupportedException("Unknown driver name given: $driver");
        }
    }
}



